home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
323_01
/
expa.asm
< prev
next >
Wrap
Assembly Source File
|
1990-08-04
|
16KB
|
843 lines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; expa.asm - support routines for EXPLOD.C. Compile with "masm /mx expa ;".
;
; NOTE:
; Make sure one of DLC or TURBOC is defined below. C compilers other
; than Datalight C and Turbo C will probably require changes to the
; segment naming. This file has been tested with the Arrowsoft Assembler
; 1.00d and MASM 5.0.
;
; (C) 1989 Dennis Lo
; You are free to use and distribute this source code, provided that the
; authors' names remain in the code, and that modified versions are clearly
; distinguished from the original.
;
; 89/06/24 Dennis Lo (V1.0) Initial release.
; 89/07/03 Dennis Lo (V1.1) Added ifdefs for linking with Turbo C.
; 89/07/26 Erik Liljencrantz Added EGA support with autodetection
; Restores previous CRT textmode on exit
; 89/08/22 Dennis Lo (V1.2) Allow frame buffer to be in any segment
; Optimized HGC/CGA frame draw loop
; Restricted EGA colours to only the bright ones
; to get rid of the flickering effect.
; 89/09/03 Erik Liljencrantz Added VGA support with autodetection
; 89/09/23 Dennis Lo Added DOS memory allocation routines
; Cosmetic changes.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;------------------------------------------------------------------
; *** IMPORTANT: Uncomment one of the following ***
;
; uncomment this for Datalight C *******
;DLC equ 1
;
; uncomment this for Turbo C ********
TURBOC equ 1
;
;------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;; SEGMENT NAMES ;;;;;;;;;;;;;;;;;;;;;;;;;
;segment names for Datalight C
ifdef DLC
pgroup group prog
prog segment byte public 'prog'
assume cs:pgroup
prog ends
dgroup group data
data segment word public 'data'
assume ds:dgroup
data ends
endif
;segment names for Turbo C
ifdef TURBOC
name t
_TEXT segment byte public 'CODE'
DGROUP group _DATA,_BSS
assume cs:_TEXT,ds:DGROUP,ss:DGROUP
_TEXT ends
_DATA segment word public 'DATA'
_d@ label byte
_DATA ends
_BSS segment word public 'BSS'
_b@ label byte
_BSS ends
endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CONST ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; HGC port addresses
config equ 03bfh
index equ 03b4h
cntrl equ 03b8h
; HGC control codes
scrn_on equ 8
grph equ 2
text equ 20h
par equ 4 ;stack offset of 1st C call parameter
DEADPOINT equ 32767 ;flag for dead point in frame table
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ifdef DLC
data segment word public 'data'
endif
ifdef TURBOC
_DATA segment word public 'DATA'
endif
Vidtype db ? ;video card type
Vidseg dw ? ;video mem segment
Vidsize dw ? ;video mem size
SaveMode DB ? ;Save video text mode
Color db ? ;Current frame colour (for EGA)
; Table of bit values for plotting points
;masktable db 128,64,32,16,8,4,2,1 ;1-pixel wide points
masktable db 192,96,48,24,12,6,3,1 ;2-pixel wide points
; HGC 6845 config tables
hgc_gtable db 35h,2dh,2eh,07h
db 5bh,02h,57h,57h
db 02h,03h,00h,00h
hgc_ttable db 61h,50h,52h,0fh
db 19h,06h,19h,19h
db 02h,0dh,0bh,0ch
; Palette register table for EGA
; Consists of colour values for registers 0-15, plus border colour
palette db 00h,07h,3ah,3bh,3ch,3eh,3fh,07h
db 3ah,3bh,3ch,3eh,07h,3ah,3bh,3ch,00h
ifdef DLC
data ends
endif
ifdef TURBOC
_DATA ends
endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ifdef DLC
prog segment byte public 'prog'
endif
ifdef TURBOC
_TEXT segment byte public 'CODE'
endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Return the number of paragraphs of memory available.
; int num_para = DosMemLeft ();
;
public _DosMemLeft
_DosMemLeft proc near
push bp
mov bp,sp
push es
mov bx,0f000h ;Call DOS malloc with a request for
mov ah,48h ; 960K to make sure it fails
int 21h
jc memleft_cont
xor ax,ax ;Error: DOS malloc() succeeded!
jmp memleft_end ;Return 0
memleft_cont:
mov ax,bx ;Return mem size remaining
memleft_end:
pop es
pop bp
ret
_DosMemLeft endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Allocate a block of memory
; int segment_addr = DosAlloc (size_in_paragraphs);
; Returns 0 if unsucessful.
;
public _DosAlloc
_DosAlloc proc near
push bp
mov bp,sp
push es
mov bx,par[bp] ;get # paragraphs requested
; add bx,15 ;# paragraphs = (# bytes + 15) / 16
; shr bx,1
; shr bx,1
; shr bx,1
; shr bx,1
mov ah,48h ;call DOS malloc
int 21h
jnc alloc_end
xor ax,ax ;if failure then return 0
alloc_end:
pop es
pop bp
ret
_DosAlloc endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Free a block of memory allocated by DosAlloc
; DosFree (int segment_addr);
; Returns 0 if successful, 1 if not.
;
public _DosFree
_DosFree proc near
push bp
mov bp,sp
push es
mov ax,par[bp] ;get segment address to free at
mov es,ax
mov ah,49h ;call DOS free
int 21h
jc free_end ;if error then return DOS err code
xor ax,ax ;else return 0
free_end:
pop es
pop bp
ret
_DosFree endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Nonblocking keyboard read - returns ASCII char
; int key = ChkKey();
;
public _ChkKey
_ChkKey proc near
push si
push di
mov ah,1
int 16h
jz nokey ;if no key then return
mov ax,0 ;else get the key out of the buffer
int 16h
mov ah,0
jmp chkret
nokey:
mov ax,0
chkret:
pop di
pop si
ret
_ChkKey endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Guess video card type. Returns 'h', 'c', 'e', or 'v'.
; int card = gr_card();
;
public _gr_card
_gr_card proc near
push bp
push si
push di
mov ah,0Fh
int 10h
MOV SaveMode,AL ;Save textmode to restore later...
MOV BL,AL
mov ax,'h' ; Mono, assume HGC
cmp bl,07h ;
je card_done ;
MOV AX,1200h
MOV BX,0FF10h
MOV CX,00FFh
INT 10h
CMP CL,12 ;CL<12
JAE Card_CGA
CMP BH,1 ;BH<=1
JA Card_CGA
CMP BL,3 ;BL<=3
JA Card_CGA
;OK, either EGA or VGA
;Use INT 10/AH=1A00 to determine which one...
MOV AX,1A00h
INT 10h
CMP AL,1Ah ;Returns AL=1Ah if function supported
JNE Card_EGA
CMP BL,08h ;VGA with analog color display
JNE Card_EGA
MOV AX,'v' ;Assume VGA
JMP SHORT Card_Done
Card_EGA:
MOV AX,'e' ;Assume EGA
JMP SHORT Card_Done
Card_CGA:
MOV AX,'c' ;Assume CGA
Card_Done:
pop di
pop si
pop bp
ret
_gr_card endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set video card type
; gr_setcard (char video_card);
;
public _gr_setcard
_gr_setcard proc near
push bp
mov bp,sp
mov ax,par[bp] ;get video_card parameter
mov Vidtype,al
;Set video mem segment
cmp al,'h'
jne not_herc
mov ax,0b000h ;Hercules
mov cx,8000h ; 32K bytes
jmp s_end
not_herc:
cmp al,'e'
jne not_ega
mov ax,0A000h ;EGA
mov cx,6D60h ; 28000 bytes (but in four planes)
jmp s_end
not_ega:
cmp al,'v'
jne not_vga
mov ax,0A000h ;VGA
mov cx,9600h ; 38400 bytes (but in four planes)
jmp s_end
not_vga:
mov ax,0b800h ;CGA
mov cx,4000h ; 16K bytes
s_end:
mov Vidseg,ax
mov Vidsize,cx
pop bp
ret
_gr_setcard endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set video card for graphics mode
; gr_gmode();
;
public _gr_gmode
_gr_gmode proc near
push bp
push es
push ds
push si
mov al,Vidtype
cmp al,'h'
jne NotHerc
call hgc_gmode ;HGC
jmp g_end
NotHerc:
cmp al,'e'
jne NotEga
call ega_gmode ;EGA
jmp g_end
NotEga:
cmp al,'v'
jne NotVga
call vga_gmode ;VGA
jmp g_end
NotVga:
call cga_gmode ;CGA
g_end:
pop si
pop ds
pop es
pop bp
ret
_gr_gmode endp
;Set HGC graphics mode, page 0
hgc_gmode:
mov dx,config
mov al,3
out dx,al
mov al,grph
lea si,hgc_gtable
mov bx,0
mov cx,4000h
call hgc_setmd
ret
;Set EGA graphics mode
ega_gmode:
mov a